﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace wpfTool
{
    /// <summary>
    /// Interaction logic for TextBoxInput.xaml
    /// </summary>
    public partial class TextBoxInput : UserControl, IPropertyGridItem
    {
        int id = 0;

        public TextBoxInput()
        {
            InitializeComponent();

            theTextBox.TextChanged += new TextChangedEventHandler(OnTextChangedHandler);
        }

        public string Text
        {
            get { return theTextBox.Text; }
            set { theTextBox.Text = value; }
        }

        void OnTextChangedHandler(object sender, TextChangedEventArgs e)
        {
            TextChangedEvent(this, Text);
        }

        public event Window1.PropertyGridItemChangeHandler TextChangedEvent;

        void IPropertyGridItem.registerItemUpdateEvent(wpfTool.PropertyGrid grid)
        {
            TextChangedEvent += new Window1.PropertyGridItemChangeHandler(grid.OnGridItemChanged);
        }

        void IPropertyGridItem.unregisterItemUpdateEvent(wpfTool.PropertyGrid grid)
        {
            TextChangedEvent -= grid.OnGridItemChanged;
        }

        int IPropertyGridItem.getID()
        {
            return id;
        }

        void IPropertyGridItem.setID(int i)
        {
            if (id != 0)
            {
                MessageBox.Show("ID Exception!");
                return;
            }

            id = i;
        }
    }
}
